package com.zbf.refresh;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/6/23  11:42
 * 描述:
 */
@Configuration
public class RefreshConfig2 {

    @Bean
   public List refreshConfig(){
        final HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory=new HttpComponentsClientHttpRequestFactory();
        httpComponentsClientHttpRequestFactory.setConnectTimeout(3000);
        httpComponentsClientHttpRequestFactory.setConnectionRequestTimeout(3000);
        httpComponentsClientHttpRequestFactory.setReadTimeout(60000);
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                try{
                    RestTemplate restTemplate=new RestTemplate(httpComponentsClientHttpRequestFactory);
                    Map mapp=new HashMap();
                    System.out.println("==========刷新配置==========");
                    restTemplate.postForObject("http://localhost:7788/actuator/refresh",mapp,String.class);
                    restTemplate=null;
                }catch (Exception e){
                    e.printStackTrace();
                }


            }
        },5,3,TimeUnit.SECONDS);

        return null;
   }

}
